package com.design.util;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 模拟库存扣减
 */
public class RedisUtil {
    private static final  AtomicInteger count = new AtomicInteger(100);
    private static final Random random = new Random();

    public static int getCount(){
        int reduice= random.nextInt(10);
        if(count.get()-reduice>0){
            count.compareAndSet(count.get(),count.get()-reduice);
        }else{
            count.compareAndSet(count.get(),0);
        }
        return count.get();
    }
}
